import React from "react"
import qs from "querystring"
import api from "../api"
export default class HttpX extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            banners: []
        }
    }
    componentDidMount() {
        /**
         * fetch 基于promise
         * 用于异步加载
         */
        fetch("http://iwenwiki.com/api/blueberrypai/getIndexBanner.php")
            .then(res => {
                return res.json();
            })
            .then(data => {
                // console.log(data);
                this.setState({
                    banners: data.banner
                })
            })

        fetch("http://iwenwiki.com/api/blueberrypai/login.php", {
            method: "POST",
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded ',
                "Accept": "application/json,text/plain"
            },
            //自己字符串拼接方法
            body: qs.stringify({
                user_id: "iwencqq.com",
                password: "iwen123",
                verification_code: "crfvw"
            })
            // body:"user_id=iwen@qq.com&password=iwen123&verification_code=crfvw"
        }).then(res => res.json())
            .then(data => {
                // console.log(data);


            })

        api.getChengpin().then(res => res.json()).then(data => {
            console.log("封装接口");
            console.log(data);
        })

        api.getLogin({
            user_id: "iwen@qq.com",
            password: "iwen123",
            verification_code: "crfvw"
        }).then(data => {
            console.log(data);
        })
    

    }

    render() {
        const { banners } = this.state;
        return (
            <div>
                {
                    banners.map((e, index) => {
                        return <li key={index}> {e.title}</li>
                    })
                }

            </div>
        )
    }
}